<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${projectName}</title>
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css">
body {
	height: 100%;
}

.fieldTitle {
	width: 100px !important;
}

.mini-tabs-leftButton, .mini-tabs-rightButton {
	display: none;
}

.mini-tabs-scrollCt {
	border-top: 0;
}

.mini-tabs-bodys {
	padding: 0;
}

.headerpan {
	margin-left: 10px;
	font-size: 14px;
	font-weight: bold;
}

#UserPhoto {
	background-image: url('<c:url value="/share/images/test.jpg"></c:url>');
	background-size: 150px 210px;
	width: 150px;
	height: 210px;
	vertical-align: middle;
	margin-left: auto;
	margin-right: auto;
}

#explain {
	color: red;
}
</style>
<script type="text/javascript">
	var isLongData = [ {
		id : 0,
		text : "短字段",
	}, {
		id : 1,
		text : "长字段",
	} ];
</script>
</head>
<body>
	<form id="dataForm">
		<div class="">
			<input id="Id" name="Id" class="mini-hidden" style="width: 100%;" />
			<table class="formContentTable type1" id="type1">
				<tr>
					<th class="fieldTitle"></th>
					<th class="fieldContent"></th>
					<th class="fieldTitle"></th>
					<th class="fieldTitle"></th>
				</tr>
				<tr>
					<td class="fieldTitle">类型名称</td>
					<td class="fieldContent" colspan="3"><input id="SourceType"
						name="SourceType" class="mini-textbox" style="width: 100%;"
						required="true" /></td>
				</tr>
				<tr>
					<td class="fieldTitle">类型描述</td>
					<td class="fieldContent" colspan="3"><textarea id="Note"
							name="Note" style="width: 100%; height: 100px;"
							required="false" class="mini-textarea" emptyText="无"></textarea></td>
				</tr>
			</table>
			<a class="mini-button" id="confirmBtn" iconCls="icon-ok"
				plain="false" onclick="save"
				style="margin-top: 10px; margin-left: 120px;">确定</a> <a
				class="mini-button" id="cancelBtn" iconCls="icon-cancel"
				plain="false" onclick="cancel"
				style="margin-top: 10px; margin-left: 50px;">取消</a>
		</div>
	</form>

	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;

		var action = '${action}';
		var id = '${id}';
		var dataOri = null;

		var form = new mini.Form("dataForm");

		SetFormData();

		function SetFormData() {
			if (action == "new") {
				var o = new Object();
				o.Id = 0;
				form.setData(o);
				dataOri = o;
				return;
			}
			var messageid = mini.loading("获取中...", "Loading");
			var urlBase = '<c:url value="/source/type/form/"></c:url>' + id;
			$.ajax({
				url : urlBase,
				type : "get",
				dataType : 'json',
				success : function(text) {
					if (!text) {
						return;
					}
					var o = mini.decode(text);
					var url = null;
					form.setData(o);
					dataOri = o;
				},
				complete : function(XMLHttpRequest, textStatus) {
					mini.hideMessageBox(messageid);
				},
				error : function(XMLHttpRequest, textStatus, errorThrown) {

				}
			});
		}
		/* 保存数据 */
		function save() {
			form.validate();
			if (form.isValid() == false) {
				parent.mini.alert("请填写必要信息后再保存!");
				return;
			}
			var formData = form.getData();
			var data = mini.encode(formData);
			var url = '<c:url value="/source/type/save/"></c:url>' + action;
			var messageid = mini.loading("保存中...", "Loading");
			$.ajax({
				url : url,
				type : "post",
				dataType : 'json',
				data : {
					"formData" : data
				},
				success : function(text) {
					if (!text) {
						top.commonTools.showTip("保存失败", 2);
						return;
					}
					var refMap = mini.decode(text);
					var isSuccess = refMap.isSuccess;
					var info = refMap.info;
					if (isSuccess) {
						action = "edit";
						top.commonTools.showTip("保存成功", 1);
						CloseWindow("ok");
					} else {
						top.commonTools.showTip(info, 2);
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
					if (messageid) {
						mini.hideMessageBox(messageid);
					}
				},
				error : function() {
					top.commonTools.showTip("操作发生错误", 2);
				}
			});
		}
		//取消
		function cancel() {
			CloseWindow("cancel");
		}
		//关闭当前弹出窗口并返回一个值告诉父页面该做什么操作
		function CloseWindow(action) {
			if (window.CloseOwnerWindow) {
				return window.CloseOwnerWindow(action);
			} else {
				window.close();
			}
		}
	</script>
</body>
</html>